<?php
/*
	Muffinz CMS - A website content management system.
	Copyright (C) 2010-2011 Sigitas Zelenkovas

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
	
	Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/

if($exec == 1){
	$cTheme->SetTitle("Global variables");
	
	if(isset($_POST['ssubmit'])){
		$buffer = "Updated: <b>";
		$updated = array();
		foreach($_POST as $name => $value){
			if($name != "ssubmit"){
				if($_SESSION['sys'][$name] != $value){
					$q->Send("UPDATE settings SET value=\"".$q->Escape($value)."\" WHERE name=\"".$q->Escape($name)."\"");
					$updated[] = array($name, $value);
				}
			}
		}
		if(count($updated) >= 1){
			$buffer = "";
			foreach($updated as $value){
				$buffer .= "<li><b>{$value[0]}</b> => {$value[1]}</li>";
			}
			$cTheme->AddModuleNotification("<b>Updated:</b> $buffer");
			$_SESSION['sys'] = $q->GetOp(true);
		}
	}
	
	$data = $q->Send("SELECT * FROM settings ORDER BY name ASC");
	$buffer = "<form method=\"post\" action=\"\"><table class=\"highlight\">";
	
	while($setting = $q->Fetch_array($data)){
		$buffer .= "<tr><td align=\"right\" nowrap>{$setting['name']}</td><td><input type=\"text\" class=\"text\" name=\"{$setting['name']}\" value=\"{$setting['value']}\" size=\"45\" /></td><td>{$setting['desc']}</td></tr>";
	}
	$buffer .= "<tr><td>&nbsp;</td><td><input type=\"submit\" class=\"button\" value=\"Save\" name=\"ssubmit\" /></td><td>&nbsp;</td></tr>";
	$buffer .= "</table></form>";
	
	$cTheme->AddModule("Global variables", $buffer, 10);
}else { header("Location: /"); }